package com.liy.framework.common.web.controller;

import java.lang.management.ManagementFactory;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;

@Component("mem")
public class SystemCustomerHealthIndicator implements HealthIndicator {

    public SystemCustomerHealthIndicator() {}

    public Health health() {
        Runtime runtime = Runtime.getRuntime();
        long use = ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage().getUsed();
        return Health.up().withDetail("total", (runtime.totalMemory() + use) / 1024L).withDetail("free", runtime.freeMemory() / 1024L).build();
    }
}
